package com.pig.serviceimpl;

import java.util.List;

import com.pig.aop.OperationLogger;
import com.pig.entity.AccountLogEntity;
import com.pig.entity.AccountUserInfoEntity;
import com.pig.file.Image;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pig.entity.AccountUserEntity;
import com.pig.mapper.AccountUserMapper;
import com.pig.service.AccountUserService;

/**
 * @author 31218
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AccountUserImpl implements AccountUserService {

	@Autowired
	private AccountUserMapper accountUserMapper;

	/**
	 * 用户登录
	 */
	@Override
	public AccountUserEntity login(String accountName, String accountPassword, Integer accountState) {
		return accountUserMapper.login(accountName,accountPassword,accountState);
	}

	/**
	 *查询日志
	 */
	@Override
	public List<AccountLogEntity> queryLog(Integer accountId) {
		List<AccountLogEntity> accountLogEntities = accountUserMapper.queryLog(accountId);
		return accountLogEntities;
	}

	/**
	 * 查询用户是否存在
	 * @return
	 */
	@Override
	public AccountUserEntity selectName(String accountName) {
		return accountUserMapper.selectName(accountName);
	}

	/**
	 * 添加日志
	 * @param accountUserEntity
	 * @return
	 */
	@Override
	public boolean insertLog(AccountLogEntity accountUserEntity) {
		return accountUserMapper.insertLog(accountUserEntity);
	}

	/**
	 *转出 & 取錢
	 */
	@OperationLogger(modelName = "/user/out",option = "取款")
	@Override
	public boolean out(String accountOutName, Double accountBalabce) {
		return accountUserMapper.out(accountOutName,accountBalabce);
	}



	/**
	 * 转入  &存錢
	 */
	@Override
	@OperationLogger(modelName = "/user/in",option = "存款")
	public boolean in(String accountInName, Double accountBalabce) {

		return accountUserMapper.in(accountInName,accountBalabce);
	}

	/**
	 * 判断用户是否存在
	 * @param accountUserEntity
	 * @return
	 */
	@Override
	public AccountUserEntity nameIs(AccountUserEntity accountUserEntity) {
		return accountUserMapper.nameIs(accountUserEntity);
	}

	/**
	 * 转账
	 */
	@Override
	@OperationLogger(modelName = "/user/transferAccounts",option = "转账")
	public boolean transferAccounts(String outName, String inName, Double balance) {
		boolean outflag = accountUserMapper.out(outName,balance);

		//int a=1/0;

		boolean inflag = accountUserMapper.in(inName,balance);
		if (outflag&&inflag){
			return true;
		}
		return false;
	}

	/**
	 * 修改密码
	 * @param accountName
	 * @param accountPassword
	 * @return
	 */
	@Override
	@OperationLogger(modelName = "/user/updatePassword",option = "修改密码")
	public boolean updatePassword(String accountName, String  accountPassword) {
		boolean flag = accountUserMapper.updatePassword(accountName,accountPassword);

		return flag;

	}

	/**
	 * 注册用户
	 * @param
	 * @return
	 */
	@Override
	public boolean register(AccountUserEntity accountUserEntity) {

		return accountUserMapper.register(accountUserEntity);
	}

	/**
	 * 注册用户信息表
	 * @param accountUserInfoEntity
	 * @return
	 */
	@Override
	public int registerInfo(AccountUserInfoEntity accountUserInfoEntity) {

		return accountUserMapper.registerInfo(accountUserInfoEntity);
	}

	/**
	 * 修改头像
	 * @param image
	 * @return
	 */
	@Override
	public int updateImage(Image image) {
		return accountUserMapper.updateImage(image);
	}


}
